/*
 * Client Handler
 */
package handler;

import gui.SettingsDialog;
import client.Startup;
import gui.Client;
import config.Content;
import gui.LoginScreen;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

/**
 * Listens to actions, listens to items
 * @author Kay van Bree
 */
public class ClientHandler implements ActionListener, ItemListener {
	protected Client client;
	
	/**
	 * Get the client
	 * @author Kay van Bree
	 * @param client The client this Handler is for.
	 */
	public ClientHandler(Client client){
		this.client = client;
	}
	
	/**
	 * Handles performed actions
	 * @author Kay van Bree
	 * @since 0.2
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == client.itemSettings) performSettingsDialog();
		if(e.getSource() == client.itemExit) System.exit(0);
		if(e.getSource() == client.itemLogout) performLogout();
	}
	
	/**
	 * This creates a new settings dialog
	 * @author Kay van Bree
	 */
	private void performSettingsDialog(){
		SettingsDialog settings = new SettingsDialog();
	}
	
	/**
	 * Create a new Login screen
	 * @author Kay van Bree
	 */
	private void performLogout(){
		Content.log.println("Logging out...");
		Startup.login = new LoginScreen();
		client.setVisible(false);
	}
	
	/**
	 * Handles item state changes
	 * @author Kay van Bree
	 * @since 0.2
	 */
	@Override
	public void itemStateChanged(ItemEvent e) {
		if(e.getSource() == client.itemShowLog){
			if(client.itemShowLog.isSelected() == true){
				Content.log.setVisible(true);
			} else {
				Content.log.setVisible(false);
			}
		}
	}
}
